package edu.must.uh.util;

public class LogHelper {
    
    
  /*  public static void saveLonginInfoLog(HttpServletRequest request,String user,String description ) throws Exception{
        BaseLog log = new BaseLog();      
        String iPAddress = Tools.getLocalIp();    
       
        String url =  request.getRequestURI();  
        log.setLogId(Tools.getUUID32());
        log.setCategoryId(1);
        log.setOperateAccount(user);
        log.setModule(url);
        log.setIPAddress(iPAddress);     
        log.setOperateTime(new Date());
        StringBuilder sBuilder =new StringBuilder();
        Enumeration enu=request.getParameterNames(); 
        while(enu.hasMoreElements()){ 
          String paraName=(String)enu.nextElement(); 
          sBuilder.append(paraName+": "+request.getParameter(paraName) +";");         
        } 
        log.setSourceContentJson(sBuilder.toString());
        log.setDescription(description);
        BaseLogImpl baseLogimpl = new BaseLogImpl();
        baseLogimpl.save(log);
        
    }
    
   public static void saveLog(HttpServletRequest request,String method,String costTime ) throws Exception{
       BaseLog log = new BaseLog();      
       String iPAddress = Tools.getLocalIp();    
       String cookiesUser = CookieUtil.getUid((HttpServletRequest)request, "LoginUser");
       String url =  request.getRequestURI();  
       log.setLogId(Tools.getUUID32()); 
       if(method.toUpperCase().contains("GET")) {
           log.setCategoryId(2); 
       }else {
           log.setCategoryId(3); 
       }
       log.setOperateAccount(cookiesUser);
       log.setModule(url);
       log.setIPAddress(iPAddress);
       log.setOperateCost(costTime);
       log.setOperateTime(new Date());
       StringBuilder sBuilder =new StringBuilder();
       Enumeration enu=request.getParameterNames(); 
       while(enu.hasMoreElements()){ 
         String paraName=(String)enu.nextElement(); 
         sBuilder.append(paraName+": "+request.getParameter(paraName) +";");         
       } 
       log.setSourceContentJson(sBuilder.toString());
       BaseLogImpl baseLogimpl = new BaseLogImpl();
       baseLogimpl.save(log);
       
   }
   
   public static void saveErrorLog(HttpServletRequest request,String method,Exception e ) throws Exception 
   {
       BaseLog log = new BaseLog();      
       String iPAddress = Tools.getLocalIp();    
       String cookiesUser = CookieUtil.getUid((HttpServletRequest)request, "LoginUser");
       String url =  request.getRequestURI();  
       log.setLogId(Tools.getUUID32()); 
       log.setCategoryId(4); 
       log.setOperateAccount(cookiesUser);
       log.setModule(url);
       log.setIPAddress(iPAddress);
       log.setDescription(e.getMessage());
       log.setOperateTime(new Date());
       StringBuilder sBuilder =new StringBuilder();
       Enumeration enu=request.getParameterNames(); 
       while(enu.hasMoreElements()){ 
         String paraName=(String)enu.nextElement(); 
         sBuilder.append(paraName+": "+request.getParameter(paraName) +";");         
       } 
       log.setSourceContentJson(sBuilder.toString());
       BaseLogImpl baseLogimpl = new BaseLogImpl();
       baseLogimpl.save(log);
       
   }*/

}
